package de.tt.test;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import de.tt.utils.SessionFactoryHelper;

public class FactoryBase {

	public static SessionFactory getSessionFactory() {
		return SessionFactoryHelper.getSessionFactory();
	}

	public static void save(Object entity) {
		Session session = null;
		Transaction tx = null;
		try {
			session = getSessionFactory().openSession();
			tx = session.beginTransaction();
			session.save(entity);
			tx.commit();
			session.close();
		} catch (RuntimeException e) {
			if (tx != null && tx.isActive()) {
				tx.rollback();
			}
			throw e;
		} finally {
			if (session.isOpen()) {
				session.close();
			}
		}

	}
}
